Skip to content

fix(ingester): skip in-flight entries when evicting from the postings cache - #7993

Merged
alanprot merged 2 commits into
cortexproject:masterfrom
alanprot:fix-postings-cache-evict-inflight
Dec 4, 2026
Merged

alanprot merged 2 commits into
cortexproject:masterfrom
alanprot:fix-postings-cache-evict-inflight

Conversation

@alanprot

@alanprot alanprot commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

What this PR does:

Fixes two regressions from #7944 in the expanded postings cache eviction.

Since #7944 an entry is linked into the LRU list when its fetch starts, not when it completes. evictLocked only looked at the list front, so an in-flight entry at the front caused two problems:

  • Byte-budget eviction dropped in-flight entries. When completed fetches pushed the cache over max_bytes, the full branch evicted the in-flight front. That frees no bytes, since an in-flight entry's bytes are not counted yet, and the next caller for that key misses and starts a duplicate fetch instead of joining the running one.
  • Expiry stopped at an in-flight front. In-flight entries are never expired, so PurgeExpiredItems returned at the front and every expired entry behind it survived until that fetch finished.

evictLocked now walks the list from the front and skips in-flight entries in both cases. The invariant that an entry is in the map if and only if it is linked in the list is unchanged. The walk passes over at most the number of fetches currently running.

Expiry still stops at the first completed entry that is not expired. Expired entries can also sit behind a fresh completed entry, because a hit moves an entry to the back without refreshing its timestamp. That predates #7944 and is left for a separate change.

A fetch that never returns now keeps its key in flight until it does: it is neither expired nor evicted for space, so later callers for that key keep joining it, each bounded by its own context. Before this change, byte pressure could evict such an entry by accident. The bound on a hung fetch is fetch_timeout, the same as for the caller running it.

A failed fetch is removed from the cache before its waiters are woken; TestLruCache_FailedFetchWithWaitersIsNotCached covers that with a waiter joined to the failing fetch.

Which issue(s) this PR fixes:
None filed. Both regressions came in with #7944, which is not released yet, so there is no CHANGELOG entry.

Checklist

  • Tests updated (TestLruCache_FullEvictionSkipsInflightEntries, TestLruCache_ExpireSkipsInflightEntries, both fail before the fix; TestLruCache_FailedFetchWithWaitersIsNotCached)
  • Documentation added (not needed)
  • CHANGELOG.md updated - fixes an unreleased change (perf(ingester): cut postings cache memory with a single-object LRU entry #7944)
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags (no new flags)
  • I did not look at code from AGPL licensed projects to make this PR

… cache

Since cortexproject#7944 an entry is linked into the LRU list when its fetch starts.
evictLocked only looked at the list front, so:

- under byte pressure it evicted an in-flight front, which frees no bytes
  and lets the next caller for that key start a duplicate fetch;
- during expiry it stopped at an in-flight front, so expired entries
  behind it survived PurgeExpiredItems.

Walk the list from the front and skip in-flight entries in both cases.

Signed-off-by: Alan Protasio <alanprot@gmail.com>
Signed-off-by: Alan Protasio <alanprot@gmail.com>
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Dec 4, 2026
@alanprot
alanprot marked this pull request as ready for review December 4, 2026 17:57
@alanprot
alanprot requested a review from a team as a code owner December 4, 2026 17:57
@alanprot
alanprot requested a review from friedrichg December 4, 2026 17:57
@alanprot
alanprot enabled auto-merge (squash) December 4, 2026 17:57
@alanprot
alanprot merged commit a754316 into cortexproject:master Dec 4, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants